home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / By the Book / Learn C++ (CodeWarrior) / Chap 07.04 - call / call.cp < prev    next >
Text File  |  1995-10-26  |  1KB  |  47 lines

  1. #include <iostream.h>
  2.  
  3.  
  4. //---------------------------------------  Item
  5.  
  6. class Item
  7. {
  8.     private:
  9.         float        price;
  10.         
  11.     public:
  12.                     Item( float itemPrice );
  13. //    Note that the default value for taxRate has been removed. The book
  14. //    uses a default value of 0. As it turns out, section 13,5 of
  15. //    the ANSI C++ draft states that an operator function cannot have
  16. //    default arguments. This faulty code compiled under THIN C++ but
  17. //    was tripped up by the CodeWarrior compiler.
  18. //
  19. //    In this version, I just removed the default value for taxRate
  20. //    and changed the call stimpyDoll() to stimpyDoll( 0 ) to
  21. //    achieve the same result. Thanks to Khurram Quereshi for figuring
  22. //    this one out!! -- Dave Mark, 10/26/95
  23.         float    operator()( float taxRate );
  24. };
  25.  
  26. Item::Item( float itemPrice )
  27. {
  28.     price = itemPrice;
  29. }
  30.  
  31. float Item::operator()( float taxRate )
  32. {
  33.     return( ((taxRate * .01) + 1) * price );
  34. }
  35.  
  36.  
  37. //---------------------------------------  main()
  38.  
  39. int    main()
  40. {
  41.     Item    stimpyDoll( 36.99 );
  42.     
  43.     cout << "Price of Stimpy doll: $" << stimpyDoll( 0 );
  44.     cout << "\nPrice with 4.5% tax:  $" << stimpyDoll( 4.5 );
  45.     
  46.     return 0;
  47. }